<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>农产品任务</title>
    <meta name="description" content="智慧农场">
    <meta name="keywords" content="智慧农场">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- <link rel="stylesheet" href="../../plugins/elementui/index.css">-->
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>农产品任务</h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>农产品任务</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-descriptions class="margin-top" title="生产人员信息" :column="3" :size="size" border>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-user"></i>
                            用户名
                        </template>
                        {{selfData.username}}
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-mobile-phone"></i>
                            手机号
                        </template>
                        {{selfData.phone}}
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-location-outline"></i>
                            农场地址
                        </template>
                        {{selfData.tfarm.province}}
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-tickets"></i>
                            生产类型
                        </template>
                        <el-tag size="small">{{selfData.tproducerType.typeName}}</el-tag>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-chat-dot-round"></i>
                            微信
                        </template>
                        {{selfData.wechat}}
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-date"></i>
                            入职日期
                        </template>
                         {{selfData.createdate}}
                    </el-descriptions-item>
                </el-descriptions>
            </div>
            <el-divider>任务列表</el-divider>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="id" label="任务ID" align="center"></el-table-column>
                <el-table-column prop="content" label="任务名称" align="center"></el-table-column>
                <el-table-column prop="productBatches.productBatch" label="产品批次" align="center"></el-table-column>
                <el-table-column prop="state" label="任务状态" align="center">
                    <template slot-scope="scope">
                        <el-tag size="small">{{ scope.row.state == '1' ? '待成功' : scope.row.state == '2' ? '待审核' :
                            scope.row.state == '3' ? '完成' : scope.row.state == '4' ? '异常' : '待下发'}}</el-tag>
                    </template>
                </el-table-column>

                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">提交任务</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 提交标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑检查项" :visible.sync="dialogFormVisible4Edit" >
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="任务ID" prop="id">
                                    <el-input :disabled="true" v-model="formData.id"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="完成描述" prop="descContent">
                                    <el-input v-model="formData.descContent"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item v-show="false" label="照片" prop="img1">
                                    <el-input v-model="formData.img1"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item v-show="false" label="照片" prop="img1">
                                    <el-upload
                                            ref="imgForm"
                                            :auto-upload="false"
                                            :http-request="upLoadFile"
                                            action=""
                                            :multiple="multiple"
                                            :limit="Number(6)"
                                            list-type="picture-card"
                                            :on-preview="handlePictureCardPreview">
                                        <i class="el-icon-plus"></i>
                                    </el-upload>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>

                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<!-- <script src="../../plugins/elementui/index.js"></script>-->
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            fileList:[],
            types:[],
            pids:[],
            projects:[],
            farms:[],
            checkedProject:[],
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryString:null//查询条件
            },
            rows:[],
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            selfData:{},
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit:false,//编辑表单是否可见
            dialogFormVisibleType:false,
            dialogFormVisibleTypes:false,
             rules: {//校验规则
                 code: [{ required: true, message: '项目编码为必填项', trigger: 'blur' }],
                 name: [{ required: true, message: '项目名称为必填项', trigger: 'blur' }]
             }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();//VUE对象初始化完成后调用分页查询方法，完成分页查询
        },
        methods: {

            upLoadFile(file){
                this.formData.append('file',file.file)
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            handleExceed(files, fileList) {
                this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
            },
            beforeRemove(file, fileList) {
                return this.$confirm(`确定移除 ${ file.name }？`);
            },
            //编辑
            handleEdit() {
                this.formData.img1=this.fileList.url;
                //进行表单校验
                this.$refs['dataEditForm'].validate((valid) => {
                    if(valid){
                        this.$refs.imgForm.submit();
                        //表单校验通过，可以提交数据
                        axios.post("/tproducer/submit",this.formData).then((res) => {
                            if(res.data.flag){
                                //弹出成功提示信息
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                });
                            }else{
                                //执行失败
                                this.$message.error(res.data.message);
                            }
                        }).finally(() => {
                            //不管成功还是失败，都调用分页查询方法
                            this.findPage();
                            //隐藏编辑窗口
                            this.dialogFormVisible4Edit = false;
                        });
                    }else{
                        //表单校验不通过
                        this.$message.error("表单数据校验失败!");
                        return false;
                    }
                });
            },
            //查询
            findPage() {
               axios.post("/tproducer/productindex").then((resp)=>{
                    //解析Controller响应回的数据，为模型数据赋值
                    console.log("相应的数据->总记录数："+resp.data.data.total);
                    // this.pagination.total = resp.data.data.total;
                    this.dataList = resp.data.data;
                    this.selfData=resp.data.data2;
                    console.log("此时的数组数据："+this.dataList);
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};//重置数据
            },
            handleUpdate(row) {
                console.log("当前行数据："+row);
                //弹出编辑窗口
                this.dialogFormVisible4Edit = true;
                //回显数据，发送ajax请求根据ID查询当前检查项数据
                this.formData.id=row.id;
            },
        }
    })
</script>
</html>